function initPage() {
    var e = $(window).height(),
    t = e - $("#head").outerHeight() - $("#guide").outerHeight();
    $("#body").height(t);
//    window.addEventListener ? (window.EVENTS_SCROLL = new IScroll("body", {
//        mouseWheel: !0,
//        scrollbars: !0
//    }), document.addEventListener("touchmove",
//    function(e) {
//        e.preventDefault()
//    },
//    !1)) : $("#events").parent().css("overflow", "auto");
    var n = $.getQueryString(),
    r = n.num ? n.num.toUpperCase() : "",
    i = parseInt(n.et, 10);
    $("#events").html("").parent().hide();
    trackPost(r, 0, 0, 0)
}
function bindLanguageSwitching() {
    var e = $(".message-head-language"),
    t = e.children(".message-head-language-list"),
    n;
    e.hover(function() {
        clearInterval(n),
        t.show()
    },
    function() {
        n = setTimeout(function() {
            t.hide()
        },
        500)
    }),
    t.hover(function() {
        clearInterval(n),
        $(this).show
    },
    function() {
        n = setTimeout(function() {
            t.hide()
        },
        500)
    })
}
function renderTranslationLang() {
    var e = translateToLang(),
    t = window.LANG.first(function(t) {
        return t.a === e
    });
    $('#ui_translate [data-role="value"]').text(t.c)
}
function doTranslate() {
    var e = translateToLang(),
    t = window.LANG.first(function(t) {
        return t.a === e
    }),
    n = $("#events"),
    r = [];
    $("DL", n).each(function() {
        var e = $(this),
        n = window.LANG.first(function(t) {
            return t.b === e.attr("data-fromLang")
        });
        $('P[data-lang="0"]', e).each(function() {
            r.push({
                element: this,
                to: t,
                from: n
            })
        })
    });
    var i = function() {
        if (r.length === 0) return;
        var e = r[0],
        t = $(e.element);
        r.splice(0, 1);
        if (e.to.a === 0 || e.to.a === e.from.a) t.show().siblings("[data-lang]").hide(),
        i();
        else {
            var n = t.closest("DD").find('P[data-lang="' + e.to.a + '"]');
            n.length > 0 ? (n.show().siblings("[data-lang]").hide(), i()) : (t.hide().siblings("[data-lang]").hide(), n = $('<p data-lang="' + e.to.a + '" class="translate-loading">' + $.i18n.track.Translating + "</p>").insertAfter(t), bingTranslate({
                from: e.from.b,
                to: e.to.b,
                text: t.text(),
                oncomplete: function(e, t) {
                    n.removeClass("translate-loading").text(e).show().siblings("[data-lang]").hide(),
                    i()
                },
                context: n
            }))
        }
    };
    i()
}
function renderTrackError(e) {
    $("#event").html(e)
}
function renderTrackPostResult(e) {
    var t = $.i18n.track,
    n = e.a,    // RE957652030SE
    r = e.d,    // 1
    i = e.e,    // 40
    s = e.f,    // 15
    o = {
        countryId: e.b, // 1924
        lang: e.ln1,    // sv
        status: e.is1,  // 1
        consuming: e.ygt1,  // 0
        cacheTime: e.ylt1,  // 0
        events: e.z1        // 2014-12-07 02:43:00
    },
    u = {
        countryId: e.c, // 1918
        lang: e.ln2,    // en
        status: e.is2,  // 1
        consuming: e.ygt2,  // 0
        cacheTime: e.ylt2,  // 2014-12-07 02:43:00
        events: e.z2    // z2
    },
    a = $("#guide");
    $('[data-role="num"]', a).text(e.a);
    var f = window.PACKAGETYPE_ENUM.first(function(e) {
        return e.a === r
    });
    $('[data-role="package-type"]', a).text(f.c).closest("LI").show();
    var l = window.PACKAGESTATE_ENUM.first(function(e) {
        return e.a === i
    });
    $('[data-role="package-state"]').text(l.c).attr("data-tip", "packagestate-" + l.a).closest("LI").show(),
    $('[data-role="package-state-icon"]').removeClass(function(e, t) {
        return (t.match(/(^|\s)package-state-icon--\d+/g) || []).join(" ")
    }).addClass("package-state-icon--" + l.a);
    var c = $("#events");
    if (e.yt) {
        var h = $.parseJSON(e.yt),
        p = $('<div class="message-guest"><h4>' + t.Guest + '</h4><ul class="clearfix"></ul></div>').prependTo(c);
        for (var d = 0; d < h.d.length; ++d) {
            var v = h.d[d],
            m = window.COUNTRY_ENUM.first(function(e) {
                return e.a === v.c
            }),
            g = window.PACKAGETYPE_ENUM.first(function(e) {
                return e.a === v.p
            }),
            y = $('<li><a href="javascript:;">' + m.b + "(" + g.c + ")</a></li>").appendTo($("UL", p)); (function(e, t) {
                $(">A", y).click(function() {
                    doRetracePost(e.a, t.a, 0)
                })
            })(g, m)
        }
    } else {
        var b = function(e, n) {
            var i = $("<dl></dl>".format(n.toLowerCase())).attr("data-fromLang", e.lang).appendTo(c),
            s = $("<dt>{0}:</dt>".format(t["Event_" + n])).appendTo(i),
            o = window.COUNTRY_ENUM.first(function(t) {
                return t.a === e.countryId
            }),
            u = window.POST_ENUM[e.countryId.toString() + r.toString()];
            e.countryId === 0 || !u ? $("<span></span>").text(o.b).appendTo(s) : $('<a target="_blank"></a>').text(o.b).attr("href", u && u.b !== "" ? u.b: "javascript:;").appendTo(s);
            var a = window.INFOSTATE_ENUM.first(function(t) {
                return t.a === e.status
            });
            s.append(" - "),
            $("<span></span>").text(a.c).attr("data-tip", e.countryId === 0 ? n.toLowerCase() + "-unknown-country": "infostate-" + a.a).addClass("infostate--" + a.a).appendTo(s);
            if (e.consuming) {
                var f = t.Event_ConsumingFormat.format(e.consuming);
                s.append(" - " + f)
            }
            if (e.cacheTime && e.cacheTime !== "2079-01-01 00:00:00") {
                var l = moment(moment.utc(e.cacheTime).toDate()).format("YYYY-MM-DD HH:mm");
                s.append(" - " + t.CacheTime.format(l))
            }
            for (var h = 0; h < e.events.length; ++h) {
                var p = e.events[h],
                d = [];
                p.c && d.push(p.c),
                p.d && d.push(p.d),
                p.z && d.push(p.z);
                var v = $('<dd><i></i><time>{0}</time> <p data-lang="0">{1}</p></dd>'.format(p.a, d.join(", "))).appendTo(i);
                h === 0 ? v.addClass("new") : h === e.events.length - 1 && v.addClass("begin")
            }
        };
        b(u, "Destination"),
        b(o, "Origin")
    }
    var w = window.EVENTS_SCROLL;
    w && w.refresh(),
    bindTips()
}
function trackPost(e, t, n, r) {
    var i = new Date;
    $.ajax({
        type: "get",
        dataType: "jsonp",
        url: "http://www.17track.net/r/handlertrack.ashx",
        crossDomain: !0,
        timeout: 14e4,
        data: {
            num: e,
            pt: isNaN(t) ? 0 : t,
            cm: isNaN(n) ? 0 : n,
            cc: isNaN(r) ? 0 : r
        },
        success: function(e) {
            var t = function(e) {
                $("#loading").hide(),
                $("#events").parent().show(),
                e.ret === 1 ? renderTrackPostResult(e.dat) : e.ret === -8 ? showCaptcha({
                    context: null,
                    callback: function(e, t) {
                        if (t !== DialogResult.OK) return;
                        window.location.reload(!0)
                    }
                }) : renderTrackError(e.msg)
            },
            n = new Date - i;
            n >= 5e3 ? t(e) : setTimeout(function() {
                t(e)
            },
            5e3 - n)
        },
        error: function(e, t, n) {
        }
    })
}
function renderTrackExpressResult(e) {
    var t = $.i18n.track,
    n = e.e,
    r = e.f,
    i = {
        countryId: e.b,
        lang: e.ln1,
        status: e.is1,
        consuming: e.ygt1,
        cacheTime: e.ylt1,
        events: e.z1
    },
    s = {
        countryId: e.c
    },
    o = $("#guide");
    $('[data-role="num"]', o).text(e.a);
    var u = window.PACKAGESTATE_ENUM.first(function(e) {
        return e.a === n
    });
    $('[data-role="package-state"]').text(u.c).attr("data-tip", "packagestate-" + u.a).closest("LI").show(),
    $('[data-role="package-state-icon"]').removeClass(function(e, t) {
        return (t.match(/(^|\s)package-state-icon--\d+/g) || []).join(" ")
    }).addClass("package-state-icon--" + u.a);
    var a = $("#events"),
    f = function(e, n) {
        var r = $("<dl></dl>".format(n.toLowerCase())).attr("data-fromLang", e.lang).appendTo(a),
        i = $("<dt></dt>").appendTo(r),
        s = window.INFOSTATE_ENUM.first(function(t) {
            return t.a === e.status
        });
        $("<span></span>").text(s.c).attr("data-tip", "infostate-" + s.a).addClass("infostate--" + s.a).appendTo(i);
        if (e.consuming) {
            var o = t.Event_ConsumingFormat.format(e.consuming);
            i.append(" - "),
            i.append(o)
        }
        if (e.cacheTime && e.cacheTime !== "2079-01-01 00:00:00") {
            i.append(" - ");
            var u = moment(moment.utc(e.cacheTime).toDate()).format("YYYY-MM-DD HH:mm");
            i.append(t.CacheTime.format(u))
        }
        for (var f = 0; f < e.events.length; ++f) {
            var l = e.events[f],
            c = [];
            l.c && c.push(l.c),
            l.d && c.push(l.d),
            l.z && c.push(l.z);
            var h = $('<dd><i></i><time>{0}</time> <p data-lang="0">{1}</p></dd>'.format(l.a, c.join(", "))).appendTo(r);
            f === 0 ? h.addClass("new") : f === e.events.length - 1 && h.addClass("begin")
        }
    };
    f(i, "Origin");
    var l = window.EVENTS_SCROLL;
    l && l.refresh(),
    bindTips()
}
function trackExpress(e, t) {
    var n = new Date;
    $.ajax({
        type: "get",
        dataType: "jsonp",
        url: window.TRACK_URL,
        crossDomain: !0,
        timeout: 14e4,
        data: {
            num: e,
            et: t
        },
        success: function(e) {
            var t = function(e) {
                $("#loading").hide(),
                $("#events").parent().show(),
                e.ret === 1 ? renderTrackExpressResult(e.dat) : e.ret === -8 ? showCaptcha({
                    context: null,
                    callback: function(e, t) {
                        if (t !== DialogResult.OK) return;
                        window.location.reload(!0)
                    }
                }) : renderTrackError(e.msg)
            },
            r = new Date - n;
            r >= 5e3 ? t(e) : setTimeout(function() {
                t(e)
            },
            5e3 - r)
        },
        error: function(e, t, n) {
            $("#loading").hide(),
            $("#events").parent().show(),
            renderTrackError(n)
        }
    })
}
function bindTips() {
    $("[data-tip]").not($("#tips_content [data-tip]")).each(function() {
        $(this).qtip({
            style: {
                classes: "qtip-default"
            },
            position: {
                my: "left top",
                at: "center right",
                viewport: $(window),
                adjust: {
                    method: "shift"
                }
            },
            content: {
                text: function(e, t) {
                    var n = $(this).attr("data-tip"),
                    r = $('#tips_content [data-tip="' + n + '"]').outerHtml();
                    return r
                }
            },
            hide: {
                fixed: !0,
                delay: 300
            }
        })
    })
}
function doRetracePost(e, t, n) {
    var r = $.getQueryString();
    r.pt = e,
    r.cm = t,
    r.cc = n;
    var i = [window.location.protocol, "//", window.location.host, window.location.pathname].join("") + "?" + $.param(r);
    document.location = i
}
function doRetraceAllError() {
    document.location.reload(!0)
}
window.RESULT_DATA = null;

// jQuery1110010061961668543518_1417872208478({"ret":1,"msg":"Ok","dat":{"a":"RS193446127NL","b":1404,"c":2104,"d":1,"e":10,"f":-1,"ln1":"en","ln2":"es","is1":1,"is2":1,"ygt1":0,"ygt2":0,"ylt1":"2014-12-06 11:34:00","ylt2":"2014-12-06 11:35:00","yt":null,"z0":{"a":"2014-12-05 03:30","b":null,"c":"NETHERLANDS (THE)","d":"","z":"Salida internacional"},"z1":[{"a":"2014-12-04 18:42","b":null,"c":"","d":"","z":"The item is at the PostNL sorting center"},{"a":"2014-11-28 02:17","b":null,"c":"","d":"","z":"The item is pre-adviced"}],"z2":[{"a":"2014-12-05 03:30","b":null,"c":"NETHERLANDS (THE)","d":"","z":"Salida internacional"},{"a":"2014-12-04 18:42","b":null,"c":"NETHERLANDS (THE)","d":"","z":"Recibido en oficina"},{"a":"2014-12-04 18:42","b":null,"c":"NETHERLANDS (THE)","d":"","z":"Procesado en oficina"}]}})
//trackPost("RE957652030SE", 0, 0, 0)
initPage();